/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package WebBrower_DAO;

import WebBrowser_DTO.WebsiteLink_DTO;
import WebBrowser_DTO.Website_DTO;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class WebsiteLink_DAO {

    public int Insert(WebsiteLink_DTO obj) {
        int ID = -1;
        try {

            SqlDataHelper helper = new SqlDataHelper();
            helper.OpenConnection();
            List<ParamDTO> params = new ArrayList<ParamDTO>();

            ParamDTO WebsiteID = new ParamDTO("WebsiteID",
                    DataTypeParam.IntegerType, obj.getWebsiteID());
            ParamDTO TenChuDe = new ParamDTO("TenChuDe", DataTypeParam.StringType,
                    obj.getTenChuDe());
            ParamDTO WebsiteLinkXpath = new ParamDTO("WebsiteLinkXpath", DataTypeParam.StringType,
                    obj.getWebsiteLinkXpath());
            ParamDTO DiaChiWebsiteLink = new ParamDTO("DiaChiWebsiteLink", DataTypeParam.StringType,
                    obj.getDiaChiWebsiteLink());
            params.add(WebsiteID);
            params.add(TenChuDe);
            params.add(WebsiteLinkXpath);
            params.add(DiaChiWebsiteLink);

            ID = helper.excuteNonQueryInsert("sp_WebsiteLink_Insert", params,
                    "sp_WebsiteLink_MaxID");

            helper.CloseConnection();
        } catch (Exception ex) {
        }
        return ID;
    }

    public boolean Update(WebsiteLink_DTO obj) {
        boolean isSuccess = false;
        try {
            SqlDataHelper helper = new SqlDataHelper();
            helper.OpenConnection();
            List<ParamDTO> listParams = new ArrayList<ParamDTO>();

            ParamDTO WebsiteLinkID = new ParamDTO("WebsiteLinkID",
                    DataTypeParam.IntegerType, obj.getWebsiteLinkID());
            ParamDTO WebsiteID = new ParamDTO("WebsiteID",
                    DataTypeParam.IntegerType, obj.getWebsiteID());

            ParamDTO TenChuDe = new ParamDTO("TenChuDe", DataTypeParam.StringType,
                    obj.getTenChuDe());
            ParamDTO WebsiteLinkXpath = new ParamDTO("WebsiteLinkXpath", DataTypeParam.StringType,
                    obj.getWebsiteLinkXpath());

            ParamDTO DiaChiWebsiteLink = new ParamDTO("DiaChiWebsiteLink", DataTypeParam.StringType,
                    obj.getDiaChiWebsiteLink());
            ParamDTO Xoa = new ParamDTO("Xoa", DataTypeParam.BooleanType,
                    obj.isXoa());

            listParams.add(WebsiteLinkID);
            listParams.add(WebsiteID);
            listParams.add(TenChuDe);
            listParams.add(WebsiteLinkXpath);
            listParams.add(DiaChiWebsiteLink);
            listParams.add(Xoa);

            isSuccess = helper.excuteNoneQueryUpdate("sp_WebsiteLink_Update",
                    listParams);

            helper.CloseConnection();

        } catch (Exception ex) {
        }
        return isSuccess;
    }

    public List<WebsiteLink_DTO> SelectByWebsiteID(int websiteid) {
        List<WebsiteLink_DTO> listResult = new ArrayList<WebsiteLink_DTO>();
        try {
            SqlDataHelper helper = new SqlDataHelper();
            helper.OpenConnection();
            ParamDTO param = new ParamDTO("WebsiteID",
                    DataTypeParam.IntegerType, websiteid);

            ResultSet data = helper.excuteQuerySelect("sp_WebsiteLink_SelectByWebsiteID", param);
            while (data.next()) {
                WebsiteLink_DTO info = new WebsiteLink_DTO();
                info.setWebsiteLinkID(data.getInt("WebsiteLinkID"));
                info.setWebsiteID(data.getInt("WebsiteID"));
                info.setTenChuDe(data.getString("TenChuDe"));
                info.setWebsiteLinkXpath(data.getString("WebsiteLinkXpath"));
                info.setDiaChiWebsiteLink(data.getString("DiaChiWebsiteLink"));
                info.setXoa(data.getBoolean("Xoa"));

                listResult.add(info);
            }
            helper.CloseConnection();

        } catch (Exception ex) {
        }
        return listResult;
    }
}
